<template>
    <div id="dr24">
        <Breadcrumb style="margin-bottom: 10px">
            <BreadcrumbItem to="/superAdmin">首页</BreadcrumbItem>
            <BreadcrumbItem>运营分析平台</BreadcrumbItem>
            <BreadcrumbItem>视频电话沟通记录</BreadcrumbItem>
        </Breadcrumb>
        <div style="padding-right: 20px">

            电话拨打状态:
            <Select v-model="type" style="width:200px;">
                <Option v-for="item in typeList" :value="item.value" :key="item.value">{{ item.label }}</Option>
            </Select> &nbsp;
            &nbsp;
            <DatePicker v-model="startTime" type="date" placeholder="选择开始时间" style="width: 150px"></DatePicker>
            至
            <DatePicker v-model="endTime" type="date" placeholder="选择结束时间" style="width: 150px"></DatePicker>
            &nbsp;
            <Button type="info" @click="search()">查询</Button>
            <!--  <Button type="info" @click="handleDownload()" style="float: right">下载报表</Button>-->
        </div>

        <Table style="margin-top: 10px" :maxWidth="1000" :minWidth="10" stripe :columns="columns" :data="data"
               v-if="data&&data.length>0"></Table>

        <br>
        <Page :total="pageTotal" :current="curPage" @on-change="pageChange"
              style="display: inline-block;padding-top: 10px;padding-bottom: 10px" show-elevator
              v-if="data&&data.length>0"/>

        <div style="padding-left: 10px;position:relative ;display: inline-block;height: 52px;line-height: 52px;top: -12px">
            总计 {{dataTotal}} 条数据
        </div>


        <div id="loading" v-if="loading">
            <div class="spinner">
                <div class="double-bounce1"></div>
                <div class="double-bounce2"></div>
            </div>
        </div>

        <Modal v-model="modeBool">
            <div slot="header" style="text-align: center;font-size: 18px;font-weight: 600">处理</div>
            <div style="text-align:left;">

                <div style="margin-top: 10px">
                    <span style="font-size: 16px;color: #f00"> 拨打电话:&nbsp;</span>
                    <RadioGroup v-model="phoneType">
                        <Radio label="未拨打" style="font-size: 16px;"></Radio>
                        <Radio label="未接通" style="font-size: 16px;"></Radio>
                        <Radio label="已接通" style="font-size: 16px;"></Radio>
                    </RadioGroup>
                </div>
                <div style="margin-top: 10px">
                    <span style="font-size: 16px;color: #f00">   用户认可:&nbsp;</span>
                    <RadioGroup v-model="userRK">
                        <Radio label="待处理" style="font-size: 16px;"></Radio>
                        <Radio label="信任" style="font-size: 16px;"></Radio>
                        <Radio label="一般" style="font-size: 16px;"></Radio>
                        <Radio label="很忙" style="font-size: 16px;"></Radio>
                        <Radio label="不信任" style="font-size: 16px;"></Radio>
                        <Radio label="伪用户" style="font-size: 16px;"></Radio>
                    </RadioGroup>
                </div>
                <div style="margin-top: 10px">
                    <span style="font-size: 16px;color: #f00">参与目的:&nbsp;</span>
                    <RadioGroup v-model="joinType">
                        <Radio label="待处理" style="font-size: 16px;"></Radio>
                        <Radio label="不信任" style="font-size: 16px;"></Radio>
                        <Radio label="赚钱" style="font-size: 16px;"></Radio>
                        <Radio label="信任" style="font-size: 16px;"></Radio>
                    </RadioGroup>
                </div>
            </div>
            <div slot="footer">
                <Button type="info" @click="modeBool=false">取消</Button>
                <Button type="info" @click="change()">确定</Button>
            </div>
        </Modal>


    </div>
</template>
<script type="text/ecmascript-6">
    import sessionUtils from '../../model/sessionUtils';
    import ipServer from '../../model/ip';
    import Axios from 'axios';

    export default {
        data() {
            return {
                phoneType: "未拨打",
                userRK: "待处理",
                joinType: "待处理",
                type: "3",
                selectMobile: "",
                dataTotal: 0,
                reffer: "",
                endTime: "",
                startTime: "",
                typeList: [
                    {
                        value: '3',
                        label: '全部'
                    },
                    {
                        value: '0',
                        label: '未拨打'
                    },
                    {
                        value: '1',
                        label: '未接通'
                    },
                    {
                        value: '2',
                        label: '已接通'
                    }
                ],
                loading: false,
                modeData: {},
                modeBool: false,
                pageTotal: 0,
                curPage: 0,
                columns: [
                    {
                        title: '手机号码',
                        key: 'mobile',
                        width: 120
                    },
                    {
                        title: '注册时间',
                        key: 'registeTime1',
                        width: 155
                    },
                    {
                        title: '用户来源',
                        key: 'source',
                        width: 120
                    }, {
                        title: '邀请人数',
                        key: 'inviteFriendCount',
                        width: 100
                    }, {
                        title: '注册数',
                        key: 'registerCount',
                        width: 80
                    }, {
                        title: '认证数',
                        key: 'validateCount',
                        width: 80
                    }, {
                        title: '拨打状态',
                        key: 'callStatus1',
                        width: 100
                    },
                    {
                        title: '用户认可度',
                        key: 'recognition1',
                        width: 150
                    }, {
                        title: '参与目的',
                        key: 'takePartIn1',

                    }, {
                        title: '处理',
                        key: 'action',
                        width: 100,
                        align: 'center',
                        render: (h, params) => {
                            return h('div', [
                                h('Button', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'
                                    },
                                    on: {
                                        click: () => {
                                            this.modeBool = true;
                                            this.modeData = params;
                                        }
                                    }
                                }, "编辑"),
                            ]);
                        }
                    }
                ],
                data: []
            }
        }
        ,
        mounted() {
            this.getData();
        }
        ,
        methods: {
            pageChange(page) {
                this.getData(page);
            },
            doChange() {
                console.log("改变了!");
                this.phoneType = "";
                this.userRK = "";
                this.joinType = "";
            },
            change() {
                var param = new URLSearchParams();
                param.append('mobile', sessionUtils.getSession("mobile"));
                param.append('token', sessionUtils.getSession("token"));
                param.append('userId', this.modeData.row.userId);

                if (this.phoneType && this.userRK && this.joinType) {

                    if (this.phoneType == "未拨打")
                        param.append('callStatus', "0");
                    if (this.phoneType == "未接通")
                        param.append('callStatus', "1");
                    if (this.phoneType == "已接通")
                        param.append('callStatus', "2");

                    if (this.userRK == "待处理")
                        param.append('recognition', "0");
                    if (this.userRK == "信任")
                        param.append('recognition', "1");
                    if (this.userRK == "一般")
                        param.append('recognition', "2");
                    if (this.userRK == "很忙")
                        param.append('recognition', "3");
                    if (this.userRK == "不信任")
                        param.append('recognition', "4");
                    if (this.userRK == "伪用户")
                        param.append('recognition', "5");

                    if (this.joinType == "待处理")
                        param.append('takePartIn', "0");
                    if (this.joinType == "不信任")
                        param.append('takePartIn', "1");
                    if (this.joinType == "赚钱")
                        param.append('takePartIn', "2");
                    if (this.joinType == "信任")
                        param.append('takePartIn', "3");

                    this.loading = true;
                    Axios.post(ipServer + "video/updateStatus", param)
                        .then(res => {
                            if (res.data.code == 0) {
                                sessionUtils.setSession("token", res.data.token);

                                if (this.phoneType) {

                                    if (this.phoneType == "未拨打") {
                                        this.data[this.modeData.index].callStatus = 0;
                                    }
                                    if (this.phoneType == "未接通") {
                                        this.data[this.modeData.index].callStatus = 1;
                                    }
                                    if (this.phoneType == "已接通") {
                                        this.data[this.modeData.index].callStatus = 2;
                                    }
                                    this.data[this.modeData.index].callStatus1 = this.phoneType;

                                }
                                if (this.userRK) {

                                    if (this.userRK == "待处理")
                                        this.data[this.modeData.index].recognition = 0;
                                    if (this.userRK == "信任")
                                        this.data[this.modeData.index].recognition = 1;
                                    if (this.userRK == "一般")
                                        this.data[this.modeData.index].recognition = 2;
                                    if (this.userRK == "很忙")
                                        this.data[this.modeData.index].recognition = 3;
                                    if (this.userRK == "不信任")
                                        this.data[this.modeData.index].recognition = 4;
                                    if (this.userRK == "伪用户")
                                        this.data[this.modeData.index].recognition = 5;

                                    this.data[this.modeData.index].recognition1 = this.userRK;
                                }
                                if (this.joinType) {

                                    if (this.joinType == "待处理")
                                        this.data[this.modeData.index].takePartIn = 0;
                                    if (this.joinType == "不信任")
                                        this.data[this.modeData.index].takePartIn = 1;
                                    if (this.joinType == "赚钱")
                                        this.data[this.modeData.index].takePartIn = 2;
                                    if (this.joinType == "信任")
                                        this.data[this.modeData.index].takePartIn = 3;

                                    this.data[this.modeData.index].takePartIn1 = this.joinType;
                                }

                                this.phoneType = "未拨打";
                                this.userRK = "待处理";
                                this.joinType = "待处理";

                                this.modeBool = false;
                            } else if (res.data.code == 3) {
                                sessionUtils.clear();
                                this.$router.push("/login");
                                this.$Message.info(res.data.msg);

                            } else {
                                this.$Message.info(res.data.msg);

                            }
                            this.loading = false;
                        })
                        .catch(err => {
                            this.loading = false;
                            this.$Message.info(err.toString());
                        });
                } else {
                    this.$Message.info("处理不能为空!");
                }


            }
            ,
            search() {
                var param = new URLSearchParams();
                param.append('mobile', sessionUtils.getSession("mobile"));
                param.append('token', sessionUtils.getSession("token"));
                if (this.type == "3") {

                } else {
                    param.append('callStatus', this.type);
                }
                this.loading = true;
                Axios.post(ipServer + "video/selectShortVideoUsers", param)
                    .then(res => {
                        if (res.data.code == 0) {
                            sessionUtils.setSession("token", res.data.token);
                            for (var i = 0; i < res.data.data.result.length; i++) {
                                res.data.data.result[i].registeTime1 = sessionUtils.timestampToTime(res.data.data.result[i].registeTime);
                                res.data.data.result[i].callTime1 = sessionUtils.timestampToTime(res.data.data.result[i].callTime);

                                if (res.data.data.result[i].recognition == "0") {
                                    res.data.data.result[i].recognition1 = "待处理";
                                }
                                if (res.data.data.result[i].recognition == "1") {
                                    res.data.data.result[i].recognition1 = "信任";
                                }
                                if (res.data.data.result[i].recognition == "2") {
                                    res.data.data.result[i].recognition1 = "一般";
                                }
                                if (res.data.data.result[i].recognition == "3") {
                                    res.data.data.result[i].recognition1 = "很忙";
                                }
                                if (res.data.data.result[i].recognition == "4") {
                                    res.data.data.result[i].recognition1 = "不信任";
                                }
                                if (res.data.data.result[i].recognition == "5") {
                                    res.data.data.result[i].recognition1 = "伪用户";
                                }


                                if (res.data.data.result[i].takePartIn == "0") {
                                    res.data.data.result[i].takePartIn1 = "待处理";
                                }
                                if (res.data.data.result[i].takePartIn == "1") {
                                    res.data.data.result[i].takePartIn1 = "不信任";
                                }
                                if (res.data.data.result[i].takePartIn == "2") {
                                    res.data.data.result[i].takePartIn1 = "赚钱";
                                }
                                if (res.data.data.result[i].takePartIn == "3") {
                                    res.data.data.result[i].takePartIn1 = "信任";
                                }


                                if (res.data.data.result[i].callStatus == "0") {
                                    res.data.data.result[i].callStatus1 = "未拨打";
                                }
                                if (res.data.data.result[i].callStatus == "1") {
                                    res.data.data.result[i].callStatus1 = "未接通";
                                }
                                if (res.data.data.result[i].callStatus == "2") {
                                    res.data.data.result[i].callStatus1 = "已接通";
                                }

                            }
                            this.pageTotal = res.data.data.dataTotal;
                            this.dataTotal = res.data.data.dataTotal;
                            this.data = res.data.data.result;
                            this.curPage = res.data.data.curPage;
                            if (this.data.length == 0)
                                this.$Message.info("查询数据不存在!");
                        } else if (res.data.code == 3) {
                            sessionUtils.clear();
                            this.$router.push("/login");
                            this.$Message.info(res.data.msg);
                        } else {
                            this.$Message.info(res.data.msg);
                        }
                        this.loading = false;
                    })
                    .catch(err => {
                        this.loading = false;
                        this.$Message.info(err);
                    });
            }
            ,
            getData(page) {
                var param = new URLSearchParams();
                param.append('mobile', sessionUtils.getSession("mobile"));
                param.append('token', sessionUtils.getSession("token"));
                if (this.type == "3") {

                } else {
                    param.append('callStatus', this.type);
                }


                if (page) {
                    param.append('pageId', page + "");
                }
                this.loading = true;
                Axios.post(ipServer + "video/selectShortVideoUsers", param)
                    .then(res => {
                        if (res.data.code == 0) {
                            sessionUtils.setSession("token", res.data.token);
                            for (var i = 0; i < res.data.data.result.length; i++) {
                                res.data.data.result[i].registeTime1 = sessionUtils.timestampToTime(res.data.data.result[i].registeTime);
                                res.data.data.result[i].callTime1 = sessionUtils.timestampToTime(res.data.data.result[i].callTime);


                                if (res.data.data.result[i].recognition == "0") {
                                    res.data.data.result[i].recognition1 = "待处理";
                                }
                                if (res.data.data.result[i].recognition == "1") {
                                    res.data.data.result[i].recognition1 = "信任";
                                }
                                if (res.data.data.result[i].recognition == "2") {
                                    res.data.data.result[i].recognition1 = "一般";
                                }
                                if (res.data.data.result[i].recognition == "3") {
                                    res.data.data.result[i].recognition1 = "很忙";
                                }
                                if (res.data.data.result[i].recognition == "4") {
                                    res.data.data.result[i].recognition1 = "不信任";
                                }
                                if (res.data.data.result[i].recognition == "5") {
                                    res.data.data.result[i].recognition1 = "伪用户";
                                }


                                if (res.data.data.result[i].takePartIn == "0") {
                                    res.data.data.result[i].takePartIn1 = "待处理";
                                }
                                if (res.data.data.result[i].takePartIn == "1") {
                                    res.data.data.result[i].takePartIn1 = "不信任";
                                }
                                if (res.data.data.result[i].takePartIn == "2") {
                                    res.data.data.result[i].takePartIn1 = "赚钱";
                                }
                                if (res.data.data.result[i].takePartIn == "3") {
                                    res.data.data.result[i].takePartIn1 = "信任";
                                }


                                if (res.data.data.result[i].callStatus == "0") {
                                    res.data.data.result[i].callStatus1 = "未拨打";
                                }
                                if (res.data.data.result[i].callStatus == "1") {
                                    res.data.data.result[i].callStatus1 = "未接通";
                                }
                                if (res.data.data.result[i].callStatus == "2") {
                                    res.data.data.result[i].callStatus1 = "已接通";
                                }
                            }
                            this.dataTotal = res.data.data.dataTotal;
                            this.data = res.data.data.result;
                            this.pageTotal = res.data.data.dataTotal;
                            this.curPage = res.data.data.curPage;
                        } else if (res.data.code == 3) {
                            sessionUtils.clear();
                            this.$Message.info(res.data.msg);
                            this.$router.push("/login");
                        } else {
                            this.$Message.info(res.data.msg);
                        }
                        this.loading = false;
                    })
                    .catch(err => {
                        this.loading = false;
                        this.$Message.info(err);
                    });
            }
        }
    }
</script>


<style scoped>
    @import "../../assets/css/loading.css";

</style>